<!DOCTYPE html>

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>登录</title>

    <!-- Custom fonts for this template-->
    <link href="css/all.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="plugin/layui/css/layui.css"/>
    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

</head>

<body class="bg-gradient-primary">

<div class="container">

    <!-- Outer Row -->
    <div class="row justify-content-center">

        <div class="col-xl-10 col-lg-12 col-md-9">

            <div class="card o-hidden border-0 shadow-lg my-5">
                <div class="card-body p-0">
                    <!-- Nested Row within Card Body -->
                    <div class="row">
                        <div class="col-lg-6 d-none d-lg-block bg-login-image"></div>
                        <div class="col-lg-6">
                            <div class="p-5">
                                <div class="text-center">
                                    <h1 class="h4 text-gray-900 mb-4">欢迎回来!</h1>
                                </div>
                                <form class="user">
                                    <div class="form-group">
                                        <input type="email" class="form-control form-control-user" id="email"
                                               name="email" placeholder="邮箱">
                                    </div>
                                    <div class="form-group">
                                        <input type="password" class="form-control form-control-user" id="password"
                                               name="password" placeholder="密码">
                                    </div>
                                    <font color="red"></font>
                                    <button type="button" class="btn btn-primary btn-user btn-block" id="loginsubmit"
                                            >登录
                                    </button>
                                    <hr>
                                </form>
                                <hr>
                                <div class="text-center">
                                    <a class="small" href="register.html">注册账号!</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>

</div>
</body>
<script src="plugin/jquery/jquery-3.3.1.min.js"></script>
<script src="plugin/util.js"></script>
<script src="plugin/layui/layui.js"></script>
<script>
    $(function () {
        layui.use('layer', function () {
            var layer = layui.layer;
        });


        $("#loginsubmit").click(function () {

            let flag = false;
            $(".user .form-group>input").each(function () {
                if ( $.emptyString($(this).val()) ){
                    flag = true;
                    layer.alert($(this).attr("placeholder")+"未填写",{icon:5})
                    return false;
                }
            })
            //是否有框未填写
            if (flag){
                return;
            }

            $.post("user/login", $(".user").serialize(), function (data) {
                //登录失败
                if (data.error){
                    layer.alert(data.message,{icon:5})
                } else{
                    //登录成功
                    layer.msg("登录成功",{icon:1,time:1000})
                    setTimeout(function () {
                        location.href = "index.html";
                    },1000)
                }
            })
        })
    })
</script>
</html>